--
-- Author: shunguo.chen
-- Date: 2018-02-06 11:20:49
--
-- ZoneIconRender 区域iconRender

local ClassRef = app.mvc.createRenderClass(...)

--data = 
function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.ZoneIconNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end     
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end 

-- 
function ClassRef:init(data)
	self.super.init(self, data)

	self:setSelected(false)

	self._ui.selected_btn:addClickEventListener(function(sender, eventType)
        if not self:isSelected() then
		    self:setSelected(not self:isSelected())
		    executeFunc(self._onClick, self)
        end
	end)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		local info = self._data
		self._ui.name:setString(info:getName())
		self._ui.map:loadTexture(info:getIcon())
	end
end

function ClassRef:setIsCurMap(b)
	self._ui.img_my:setVisible(b and self._data:isCurZone())
end

function ClassRef:isSelected()
    return not self._ui.selected_btn:isBright()
end
function ClassRef:setSelected(b)
    self._ui.selected_btn:setBright(not b)
    self._ui.name:setVisible(b)
    self._ui.quan:setVisible(not b)
    self._ui.mask:setVisible(not b)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef